
* ------------------------------------------------------------------------------
*
* Paper: A Lockdown Index to Assess the Distributional Impact of the Coronavirus
* Authors: Marius Faber, Andrea Ghisletta, Kurt Schmidheiny
* Date:    June 2020
*
*
* REPLICATION FILE: 
* A_02_results.do
*
* DESCRIPTION:
* C_00 Unemployment and short time work [Figure 1]
* C_01 Bar graphs:
	* C_01_01 Industry (both indexes) [Figures 2 and A1]
	* C_01_02 Urban (both indexes) [Figures 6 and A5]
	* C_01_03 Income (both indexes) [Figures 7 and A6]
	* C_01_04 Age (both indexes) [Figures 8 and A7]
	* C_01_05 Gender and civil status (both indexes) [Figures 9 and A8]
* C_02 Maps:
	* C_02_01 Cantons (both indexes) [Figures 3 and A2]
	* C_02_02 Large labor market region (both indexes) [Figures 4 and A3]
	* C_02_03 Labor market region (both indexes) [Figures 5 and A4]
	* C_02_04 Cantons (comparis users) [Figure 13]
* C_03 Scatter plots:
	* C_03_01 Industry-level short-time work vs lockdown index [Figure 10]
	* C_03_02 Industry-level short-time work vs lockdown index, public sector 
	*		  adjusted [Figure 11]
	* C_03_03 Canton-level short-time work vs lockdown index, public sector 
	*		  adjusted [Figure 12]
	* C_03_04 Canton-level comparis usage vs lockdown index, public sector 
	*		  adjusted [Figure 14]
	* C_03_05 Industry-level unemployment vs lockdown index [Figure 15]
	* C_03_06 Canton-level unemployment vs lockdown index [Figure 16]
*
* Figure A9 is produced in separate .xlsx file named "A_stw_canton_industry"
*
* ------------------------------------------------------------------------------


* ------------------------------------------------------------------------------
* 0 Settings 
* ------------------------------------------------------------------------------

* 0.1 System settings
clear 				all
set more 			off, perm
pause 				on
set autotabgraphs 	on, perm

* 0.2 Set working directories
cd "yourpath" 						// replace with path containing this replication folder


* 0.3 Download packages
/*
ssc install palettes,  replace
ssc install colrspace, replace
ssc install spmap,     replace
ssc install shp2dta,   replace
ssc install mif2dta,   replace
ssc install _gwtmean,  replace
*/

* 0.4 Start logging
cap log close
cap log using "D_01_results.log", append


* ------------------------------------------------------------------------------
* C_00 Unemployment and short time work 
* ------------------------------------------------------------------------------
use "B_01_input_unemp_1993-2020.dta", clear

merge 1:1 date using "B_01_input_stw_2004-2020.dta"
drop if _merge==1 										// only after 2004
drop _merge

gen month=mofd(date)
format month %tm
tsset month
label val month month

destring stw_paid stw_approved , replace
gen stw_tot=stw_approved
replace stw_tot=stw_paid if !missing(stw_paid)

replace stw_approved=. if Monat=="Januar 2020" | Monat=="Februar 2020"

grstyle init
grstyle set plain, horizontal grid

graph bar unemployed_nr stw_tot, over(month, relabel(1 " " 2 " " 3 " " 4 "2004-04" 5 " " 6 " " 7 " " 8 " " 9 " " 10 " " 11" " 12" " 13" " 14" " 15 " " 16"2005-04" 17" " 18" " 19" " 20" " 21" " 22" " 23" " 24" " 25" " 26" " 27" " 28"2006-04" 29" " 30 " " 31" " 32" " 33" " 34" " 35" " 36" " 37" " 38" " 39" " 40"2007-04" 41" " 42" " 43" " 44" " 45" " 46" " 47" " 48" " 49" " 50 " " 51"2008-04" 52" " 53" " 54" " 55" " 56" " 57" " 58" " 59" " 60 " " 61" " 62" " 63"2009-04" 64" " 65" " 66" " 67" " 68" " 69" " 70 " " 71" " 72" " 73" " 74" " 75"2010-04" 76" " 77" " 78" " 79" " 80 " " 81" " 82" " 83" " 84" " 85" " 86" " 87" " 88"2011-04" 89" " 90 " " 91" " 92" " 93" " 94" " 95" " 96" " 97" " 98" " 99" " 100 "2012-04" 101" " 102" " 103" " 104" " 105" " 106" " 107" " 108" " 109" " 110 " " 111" " 112"2013-04" 113" " 114" " 115" " 116" " 117" " 118" " 119" " 120 " " 121" " 122" " 123" " 124"2014-04" 125" " 126" " 127" " 128" " 129" " 130 " " 131" " 132" " 133" " 134" " 135" " 136"2015-04" 137" " 138" " 139" " 140 " " 141" " 142" " 143" " 144" " 145" " 146" " 147" " 148"2016-04" 149" " 150 " " 151" " 152" " 153" " 154" " 155" " 156" " 157" " 158" " 159" " 160 "2017-04" 161" " 162" " 163" " 164" " 165" " 166" " 167" " 168" " 169" " 170 " " 171" " 172"2018-04" 173" " 174" " 175" " 176" " 177" " 178" " 179" " 180 " " 181" " 182" " 183" " 184"2019-04" 185" " 186" " 187" " 188" " 189" " 190 " " 191" " 192" " 193" " 194" " 195" " 196"2020-04") label( labsize(10pt) angle(45))) stack ///
	  bar(1, color(navy*1.3) lwidth(0.1pt)) bar(2, color(red*0.6) lwidth(0.1pt)) 														///
	  ytitle("Number of beneficiaries" " ", size(10pt))																					///
	  ylabel(0 100000 500000 1000000 1500000 2000000, labsize(10pt) format(%12.0fc)) 													///
	  legend(order(1 "Unemployment" 2 "Short-time work*") region(lwidth(none)) position(10) bmargin(large) ring(0) rows(4) size(10pt)) 	///
	  graphregion(color(white)) 																										/// 
	  note(" " "Source: Own representation with SECO labor market data" "*Paid short-time work until February 2020, approved short-time work applications from March 2020." " Between 2009 and 2014, 84% of the approved short-time work applications were paid out on average.", size(8pt) span)
	
graph export "C_00_stackedbar_kza_unemp.pdf", replace

* Export .csv file
preserve
keep Monat unemployed_nr stw_tot stw_paid stw_approved
order Monat unemployed_nr stw_tot stw_paid stw_approved
export delimited using "C_00_stackedbar_kza_unemp.csv", replace
restore

* ------------------------------------------------------------------------------
* C_01 Bar Graphs 
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* C_01_01 Industries (both indexes) 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_noga2008_seco.dta", clear

collapse (mean) lockdown_index lockdown_index_adj home_office_index (sum) weights, by(noga2008_seco)

merge 1:1 noga2008_seco using "B_01_input_unemp_noga.dta", nogenerate
drop if noga2008_seco_title==""
order noga2008_seco noga2008_seco_title noga2008_seco_title_eng d_pct_unempl_feb20_mar20 d_pct_unempl_mar19_mar20 lockdown_index lockdown_index_adj home_office_index  weights

* Home-office index [Figure A1]
graph hbar (asis) home_office_index,  over(noga2008_seco_title_eng, label(labsize(9pt)) gap(200) sort(1)) ysize(6) nofill 	 						 		///
				ytitle("Home-office index", size(9pt)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(9pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(9pt))	///
				graphregion(color(white)) legend(off) 																										///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																///
				bar(1, color("dkgreen"*0.8)) 																												///

graph export "C_01_bar_industry_homeoffice.pdf", replace 

* Mark essential sectors with asterisk and shorten some names
replace noga2008_seco_title_eng="Public administration, social security*" 			 if noga2008_seco_title_eng=="Public administration, social security"
replace noga2008_seco_title_eng="Health and social care*"				 			 if noga2008_seco_title_eng=="Health and social care"
replace noga2008_seco_title_eng="Wholesale trade*"				 					 if noga2008_seco_title_eng=="Wholesale trade"
replace noga2008_seco_title_eng="Retail trade*"				 						 if noga2008_seco_title_eng=="Retail trade"
replace noga2008_seco_title_eng="Financial and insurance activities*"				 if noga2008_seco_title_eng=="Financial and insurance activities"
replace noga2008_seco_title_eng="Car trade and repair*"			 					 if noga2008_seco_title_eng=="Car trade and repair"

* Lockdown index [Figure 2]
graph hbar (asis) lockdown_index, over(noga2008_seco_title_eng, label(labsize(9pt)) gap(200) sort(1)) ysize(6) nofill 										///
				ytitle("Lockdown Index", size(9pt)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(9pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(9pt))		///
				graphregion(color(white)) legend(off)																										///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET" "*Completely or partially essential sectors", size(8pt) span)					///
				bar(1, color("maroon"*0.8)) 																												///

graph export "C_01_bar_industry_lockdown.pdf", replace 

* Export .csv file
preserve
keep noga2008_seco noga2008_seco_title lockdown_index home_office_index d_pct_unempl_mar19_mar20 d_pct_unempl_feb20_mar20 weights
order noga2008_seco noga2008_seco_title lockdown_index home_office_index d_pct_unempl_mar19_mar20 d_pct_unempl_feb20_mar20 weights
export delimited using "C_01_bar_industry.csv", replace
restore

* ------------------------------------------------------------------------------
* C_01_02 Urban (both indexes) 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_urban.dta", clear

* Lockdown index [Figure 6]
graph hbar (asis) lockdown_index, over(urban, relabel(2 `""Periurban areas" "and rural centres" "') label(labsize(medsmall)) gap(100) sort(urban) descending)  nofill	///
				ytitle("Lockdown Index", size(medsmall)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(medsmall) glwidth(0.15)) blabel(bar, format(%9.2f) size(medsmall)) 	///
				graphregion(color(white)) legend(off)  aspect(0.78)  																									///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																			///
				bar(1, color("maroon"*0.8))																																///

graph export "C_01_bar_urban_lockdown.pdf", replace 


* Home-office index [Figure A5]
graph hbar (asis) home_office_index, over(urban, relabel(2 `""Periurban areas" "and rural centres" "') label(labsize(medium)) gap(100) sort(inc_class) descending)  nofill 	///
				ytitle("Home-office index", size(medsmall)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(medsmall) glwidth(0.15)) blabel(bar, format(%9.2f) size(medsmall)) 	///
				graphregion(color(white)) legend(off) aspectratio(0.78) 																									///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																				///
				bar(1, color("dkgreen"*0.8)) 																																///

graph export "C_01_bar_urban_homeoffice.pdf", replace 

* Export .csv file
keep urban lockdown_index home_office_index weights
order urban lockdown_index home_office_index weights
export delimited using "C_01_bar_urban.csv", replace


* ------------------------------------------------------------------------------
* C_01_03 Income (both indexes) 
* ------------------------------------------------------------------------------

* Import income data
use "B_03_privacyconform_inc_class.dta", clear

drop if inc_class<=0

* Lockdown index [Figure 7]
graph hbar (asis) lockdown_index, over(inc_class, label(labsize(9pt)) gap(150) sort(inc_class) descending)  nofill 										///
				ytitle("Lockdown index", size(9pt)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(9pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(9pt)) 	///
				graphregion(color(white)) legend(off) aspectratio(0.78)	 graphregion(margin(10 -10 2 2)) 												///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)															///
				bar(1, color("maroon"*0.8)) 																											///

graph export "C_01_bar_income_lockdown.pdf", replace 


* Home-office index [Figure A6]
graph hbar (asis) home_office_index, over(inc_class, label(labsize(9pt)) gap(150) sort(inc_class) descending)  nofill 										///
				ytitle("Home-office index", size(9pt)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(9pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(9pt)) 	///
				graphregion(color(white)) legend(off) aspectratio(0.78)	 graphregion(margin(10 -10 2 2)) 													///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																///
				bar(1, color("dkgreen"*0.8)) 																												///

graph export "C_01_bar_income_homeoffice.pdf", replace 

* Export .csv file
keep inc_class lockdown_index home_office_index weights
order inc_class lockdown_index home_office_index weights
export delimited using "C_01_bar_income.csv", replace

* ------------------------------------------------------------------------------
* C_01_04 Age (both indexes) 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_agegroup", clear

* Lockdown index [Figure 8]
graph hbar (asis) lockdown_index, over(agegroup, label(labsize(10pt)) gap(130) sort(agegroup))  nofill 														///
				ytitle("Lockdown Index", size(pt10)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(10pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(10pt)) 	///
				graphregion(color(white)) legend(off)																										///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																///
				bar(1, color("maroon*0.8")) 																												///
				
graph export "C_01_bar_age_lockdown.pdf", replace 

* Home-office index [Figure A7]
graph hbar (asis) home_office_index, over(agegroup, label(labsize(pt10)) gap(130) sort(agegroup))  nofill 														///
				ytitle("Home-office index", size(pt10)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(10pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(10pt))	///
				graphregion(color(white)) legend(off)																											///
				note(" ""Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																	///
				bar(1, color("dkgreen*0.8")) 																													///

graph export "C_01_bar_age_homeoffice.pdf", replace

* Export .csv file
keep agegroup lockdown_index home_office_index weights
order agegroup lockdown_index home_office_index weights
export delimited using "C_01_bar_age.csv", replace

* ------------------------------------------------------------------------------
* C_01_05 Gender and civil status (both indexes) 
* ------------------------------------------------------------------------------

* Import gendercivil data
use "B_03_privacyconform_gend_civil", clear

* Append gender data
preserve
use "B_03_privacyconform_male", clear
tempfile junk
save `junk', replace
restore 
append using `junk'

* Adjust variables
replace gend_civil=-1 if gend_civil==.
label define gend_civil_lbl -1 "All", add
label value gend_civil gend_civil_lbl

replace male=0 if gend_civil==1 | gend_civil==2
replace male=1 if gend_civil==3 | gend_civil==4

gen group=.
replace group=1 if male==0 & gend_civil==-1
replace group=2 if gend_civil==1
replace group=3 if gend_civil==2
replace group=4 if male==1 & gend_civil==-1
replace group=5 if gend_civil==3
replace group=6 if gend_civil==4

label define group_lbl 1 "Women" 2 "Women, unmarried" 3 "Women, married" 4 "Men" 5 "Men, unmarried" 6 "Men, married"
label value group group_lbl

gen subgroup=0
replace subgroup=1 if group==2 | group==3 | group==5 | group==6

separate lockdown_index, by(subgroup)
separate home_office_index, by(subgroup)

* Lockdown index [Figure 9]
graph hbar (asis) lockdown_index0 lockdown_index1, over(group, label(labsize(10pt))) nofill 																///
				ytitle("Lockdown Index", size(10pt)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(10pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(10pt))	///
				graphregion(color(white)) legend(off)																										///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																///
				bar(1, color("maroon"*0.8)) 																												///
				bar(2, color("maroon"*0.4)) 
 
graph export "C_01_bar_gendercivil_lockdown.pdf", replace 

* Home-office index [Figure A9]
graph hbar (asis) home_office_index0 home_office_index1, over(group, label(labsize(10pt))) nofill 																///
				ytitle("Home-office index", size(10pt)) ylabel(0.0(0.1)1.0, format(%2.1f) labsize(10pt) glwidth(0.15)) blabel(bar, format(%9.2f) size(10pt))	///
				graphregion(color(white)) legend(off)																											///
				note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)																	///
				bar(1, color("dkgreen"*0.8)) 																													///
				bar(2, color("dkgreen"*0.4)) 
				
graph export "C_01_bar_gendercivil_homeoffice.pdf", replace 

* Export .csv file
keep group lockdown_index home_office_index
order group lockdown_index home_office_index
export delimited using "C_01_bar_gendercivil.csv", replace

* ------------------------------------------------------------------------------
* C_02 Maps 
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* C_02_01 Cantons 
* ------------------------------------------------------------------------------

* Preparation
* Import data
use "B_03_privacyconform_company_canton.dta", clear

* Merge geo data
* Cantonal info
rename company_canton KT
merge m:1 KT using "B_01_input_geo_g3k11", keep(match master)
drop _merge
rename KT canton
* Cantonal capitals
rename canton Kanton
merge m:1 Kanton using "B_01_input_geo_capitals", keep(master match) keepusing(xcoord ycoord)
drop _merge
rename Kanton canton
* Centers' coordinates
merge m:1 id using "B_01_input_geo_g3k11coo_center", keep(master match)
drop if _merge!=3
drop _merge

* Compute cantonal Weights (for .csv export)
bys canton : egen weights_ct=sum(weights)

* Lockdown index map [Figure 3]
format lockdown_index %5.2f
colorpalette hcl, reds n(8) reverse nograph
#delimit ;
spmap  lockdown_index using "B_01_input_geo_g3k11coo.dta", 
	plotregion(margin(zero) icolor(white))
	id(id)
    clmethod(custom) clbreaks(0.21 0.24 0.27 0.30 0.33 0.36 0.39 0.42 0.50)
	legend(position(11) size(8.5pt) title("Lockdown index", size(8.5pt) bexpand justification(left))) legstyle(2)
	ndfcolor(white) fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
	ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 ) /// gs0 = black, gs16=white
	osize(0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt)
	polygon(data("B_01_input_geo_g3s11coo")fcolor(white) ocolor(white)) // Lakes
	label(xcoord(x_center) ycoord(y_center) label(company_canton_title) color(black) size(8.5pt))
	note("Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)
;
#delimit cr

graph export "C_02_map_firmcanton_lockdown.pdf", replace

* Home-office index map [Figure A2]
format home_office_index %5.2f
colorpalette hcl,  greens n(10) reverse  nograph
#delimit ;
spmap  home_office_index using "B_01_input_geo_g3k11coo.dta", 
	plotregion(margin(zero) icolor(white))
	id(id)
	clmethod(custom) clbreaks(0.10(0.05)0.60)
	legend(position(11) size(8.5pt) title("Home-office index", size(8.5pt) bexpand justification(left))) legstyle(2)
	ndfcolor(white) fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
	ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 ) /// gs0 = black, gs16=white
	osize(0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt)
	polygon(data("B_01_input_geo_g3s11coo")fcolor(white) ocolor(white)) // Lakes
	label(xcoord(x_center) ycoord(y_center) label(company_canton_title) color(black) size(8.5pt))
	note("Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)
;
#delimit cr			
graph export "C_02_map_firmcanton_homeoffice.pdf", replace

* Export .csv file
collapse (mean) lockdown_index home_office_index weights_ct, by(canton company_canton_title)
order canton company_canton_title lockdown_index home_office_index weights_ct
export delimited using "C_02_map_firmcanton.csv", replace


* ------------------------------------------------------------------------------
* C_02_02 Large labor market regions 
* ------------------------------------------------------------------------------

* Preparation
* Import data
use "B_03_privacyconform_llmr2018.dta", clear

* Merge geo data
gen _ID=llmr2018
merge m:1 _ID using "B_01_input_geo_llmrcoo_2007_pnts", keep(match master)
rename _X x_center
rename _Y y_center

* Compute weights (for .csv export)
bys llmr2018 : egen weights_llmr2018=sum(weights)

* Lockdown index map [Figure 4]

format lockdown_index %5.2f

colorpalette hcl, reds n(8) reverse nograph
#delimit ;
spmap  lockdown_index using "B_01_input_geo_llmrcoo_2007_poly.dta",
	plotregion(margin(zero) icolor(white))
    id(_ID)
    clmethod(custom) clbreaks(0.26(0.02)0.40)
    legstyle(2) legend(position(11) size(8.5pt) title("Lockdown index", size(8.5pt) bexpand justification(left)))
    ndfcolor(white) fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
    ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16) /// gs0 = black, gs16=white
    osize(0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt)
    polygon(data("B_01_input_geo_seen11coo_2007_poly") fcolor(white) ocolor(white)) // Lakes
    label(xcoord(x_center) ycoord(y_center) label(llmr2018_title) length(50) color(gs1) size(7.5pt))
	note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt))
;
#delimit cr   	
graph export "C_02_map_LLMR2018_lockdown.pdf", replace

* Home-office index map [Figure A3]
format home_office_index %5.2f
colorpalette hcl, greens reverse n(7) nograph
#delimit ;
spmap  home_office_index using "B_01_input_geo_llmrcoo_2007_poly.dta",
	plotregion(margin(zero) icolor(white))
    id(_ID)
    clmethod(custom) clbreaks(0.27(0.03)0.48)
    legstyle(2) legend(position(11) size(8.5pt) title("Home-office index", size(8.5pt) bexpand justification(left)))
    ndfcolor(white) fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
    ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16) /// gs0 = black, gs16=white
    osize(0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt)
    polygon(data("B_01_input_geo_seen11coo_2007_poly") fcolor(white) ocolor(white)) // Lakes
    label(xcoord(x_center) ycoord(y_center) label(llmr2018_title) length(50) color(gs1) size(7.5pt))
	note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt))
;
#delimit cr  
graph export "C_02_map_LLMR2018_homeoffice.pdf", replace

* Export .csv file
collapse (mean) lockdown_index home_office_index weights_llmr2018, by(llmr2018 llmr2018_title)
order llmr2018 llmr2018_title lockdown_index home_office_index weights_llmr2018
export delimited using "C_02_map_LLMR2018", replace


* ------------------------------------------------------------------------------
* C_02_03 Labor market regions 
* ------------------------------------------------------------------------------
* Preparation
* Import data
use "B_03_privacyconform_lmr2018", clear

* Merge geo data
gen _ID=lmr2018
merge m:1 _ID using "B_01_input_geo_lmrcoo_2007_pnts", keep(match master)
rename _X x_center
rename _Y y_center

* Compute LMR weights (for .csv export)
bys lmr2018 : egen weights_lmr2018=sum(weights)

* Control SAKE extrapolation
gen extrapolation=.
replace extrapolation=1 if obs_count>50
replace extrapolation=2 if obs_count<51
replace extrapolation=3 if obs_count<6
label def extrap_lbl 1 "Extrapolation: OK" 2 "Extrapolation: Caution" 3 "Extrapolation: not possible"
label value extrapolation extrap_lbl
tab extrapolation
tab lmr2018_title if extrapolation==2

* Lockdown index map [Figure 5]
format lockdown_index %5.2f

colorpalette hcl, reds n(8) reverse nograph
#delimit ;
spmap  lockdown_index using "B_01_input_geo_lmrcoo_2007_poly.dta",
	plotregion(margin(zero) icolor(white))
    id(_ID)
    clmethod(custom) clbreaks(0.22 0.25 0.28 0.31 0.34 0.37 0.40 0.43 0.50)
    legstyle(2) legend(position(11) size(8.5pt) title("Lockdown index", size(8.5pt) bexpand justification(left)))
    ndfcolor(white) fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
    ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16) /// gs0 = black, gs16=white
    osize(0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt)
	polygon(data("B_01_input_geo_seen11coo_2007_poly") fcolor(white) ocolor(white)) //Lakes
	note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt) span)
;
#delimit cr 

graph export "C_02_map_lmr2018_lockdown.pdf", replace


* Home-office index map [Figure A4]
format home_office_index %5.2f

colorpalette hcl, greens n(5) reverse nograph
#delimit ;
spmap  home_office_index using "B_01_input_geo_lmrcoo_2007_poly.dta",
	plotregion(margin(zero) icolor(white)) 
    id(_ID)
	clmethod(custom) clbreaks(0.10(0.10)0.60)
    legstyle(2) legend(position(11) size(8.5pt) title("Home-office index", size(8.5pt) bexpand justification(left)))
    ndfcolor(white) fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
    ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16) /// gs0 = black, gs16=white
    osize(vthin vthin vthin vthin vthin vthin vthin vthin)
    polygon(data("B_01_input_geo_seen11coo_2007_poly") fcolor(white) ocolor(white) osize(vvthin))  // Lakes
	note(" " "Source: Own calculations with SLFS 2018 and O*NET", size(8pt))
;
#delimit cr   			
graph export "C_02_map_lmr2018_homeoffice.pdf", replace

* Export .csv file
collapse (mean) lockdown_index home_office_index weights_lmr2018, by(lmr2018 lmr2018_title)
order lmr2018 lmr2018_title lockdown_index home_office_index weights_lmr2018
export delimited using "C_02_map_lmr2018.csv", replace


* ------------------------------------------------------------------------------
* C_02_04 Cantons (comparis users) 
* ------------------------------------------------------------------------------

use "B_03_privacyconform_company_canton.dta", clear

* Cantonal info
rename company_canton KT
merge m:1 KT using "B_01_input_geo_g3k11", keep(match master)
drop _merge
rename KT canton
* Cantonal capitals
rename canton Kanton
merge m:1 Kanton using "B_01_input_geo_capitals", keep(master match) keepusing(xcoord ycoord)
drop _merge
rename Kanton canton
* Centers' coordinates
merge m:1 id using "B_01_input_geo_g3k11coo_center", keep(master match)
drop if _merge!=3
drop _merge
* Map
drop if home_office_index==.

* Generate cantonal weights
bys canton : egen weights_ct=sum(weights)

contract canton company_canton_title lockdown_index home_office_index id x_center y_center weights_ct

decode company_canton_title, gen(compc_title)

merge 1:1 canton using "B_01_input_comparis_users_canton.dta", nogenerate


replace sh_ka=. if german==0

* Share KA users map [Figure 13]
format sh_ka %5.2f
colorpalette hcl, blues n(8) reverse /*greens n(10)*/ nograph
#delimit ;
spmap  sh_ka using "B_01_input_geo_g3k11coo.dta", 
	plotregion(margin(zero) icolor(white))
	id(id) 
    clmethod(custom) clbreaks(4.00 4.50 5.00 5.50 6.00 6.50 7.00 7.50)
	legend(position(11) size(8.5pt) title("User share of the" "short-time work calculator in %", size(8.5pt) bexpand justification(left))) legstyle(2)
	ndfcolor(gray*0.2) ndocolor(white) ndsize(0.3pt) ndlabel("Not available") fcolor(`r(p)') /// http://repec.sowi.unibe.ch/stata/palettes/colors.html
	ocolor(gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 gs16 ) /// gs0 = black, gs16=white
	osize(0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt 0.3pt)
	polygon(data("B_01_input_geo_g3s11coo")fcolor(white) ocolor(white)) // Lakes
	label(xcoord(x_center) ycoord(y_center) label(compc_title) color(black) size(8.5pt))
	note("Source: Own representation with aggregated user data from comparis.ch", size(8pt) span)
;
#delimit cr
graph export "C_02_map_comparis_canton.pdf", replace

* Export .csv file
keep if german==1
keep canton_str compc_title sh_ka
order canton_str compc_title sh_ka
rename sh_ka Comparis_users_share
order canton compc_title Comparis_users_share
export delimited using "C_02_map_comparis_canton.csv", replace

* ------------------------------------------------------------------------------
* C_03 Scatter plots 
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* C_03_01 Industry-level short-time work vs lockdown index 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_noga2008_kza.dta", clear

merge 1:1 noga2008_kza using "B_01_input_stw_noga", nogenerate
drop if noga2008_kza_title==""

* Scatter plots and bivariate regressions
capture drop noga2008_seco_select
generate noga2008_seco_select = ""

replace noga2008_seco_select = "Hospitality" if noga2008_kza=="55-56"
replace noga2008_seco_select = "Health and social care" if noga2008_kza=="86-88"
replace noga2008_seco_select = "Machinery manufacturing" if noga2008_kza=="28"
replace noga2008_seco_select = "Agriculture" if noga2008_kza=="01-03"
replace noga2008_seco_select = "Education" if noga2008_kza=="85"

* Scatter short-time work vs. lockdown index (unadjusted) [Figure 10]
twoway ///
	(lfit relative_sec lockdown_index [aw=weights], lcolor("231 24 55") lpattern(solid) lwidth(0.25)) 			///
	(scatter relative_sec lockdown_index [aw=weights], 															///
		msize(0.4) mcolor(navy%70) mlwidth(0.25) 																///
	) 																											///
	(scatter relative_sec lockdown_index, msymbol(none) mlabsize(8pt) 											///
		mlabel(noga2008_seco_select) mlabcolor(navy) mlabposition(5)  mlabgap(1.25) 							///
	) 																											/// 
	, 																											///
	xtitle(" " "Lockdown index" " ", size(10pt)) 																///
	xlabel(0(0.1)0.7, format(%3.2f) labsize(10pt)) 																///
	ytitle("Approved short-time work applications" "per worker, March-April 2020 (in %)" " ", size(10pt)) 		///
	ylabel(0(10)80, labsize(10pt))																				///
	legend(off) 																								///
	graphregion(color(white)) 																					/// 
	note(" " "Source: Own calculation with SLFS 2018, O*NET, SECO labor market report and STATENT", size(8pt) span)	

graph export "C_03_scatter_stw_lockdown_industry.pdf", replace

* Regression short-time work vs. lockdown index (unadjusted)
reg relative_sec lockdown_index [aw=weights], robust

* Export .csv file
keep noga2008_kza noga2008_kza_title relative_sec lockdown_index weights
order noga2008_kza noga2008_kza_title relative_sec lockdown_index weights
rename relative_sec genehmigte_STW
export delimited using "C_03_scatter_stw_lockdown_industry.csv", replace


* ------------------------------------------------------------------------------
* C_03_02. Industry-level short-time work vs lockdown index, public sector adj. 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_noga2008_kza.dta", clear

merge 1:1 noga2008_kza using "B_01_input_stw_noga", nogenerate
drop if noga2008_kza_title==""

* Scatter plots and bivariate regressions
capture drop noga2008_seco_select
generate noga2008_seco_select = ""

replace noga2008_seco_select = "Hospitality" if noga2008_kza=="55-56"
replace noga2008_seco_select = "Health and social care" if noga2008_kza=="86-88"
replace noga2008_seco_select = "Machinery manufacturing" if noga2008_kza=="28"
replace noga2008_seco_select = "Agriculture" if noga2008_kza=="01-03"
replace noga2008_seco_select = "Education" if noga2008_kza=="85"

* Scatter short-time work vs. lockdown index (pub. sec. adjusted) [Figure 11]
twoway ///
	(lfit relative_sec lockdown_index_adj [aw=weights], lcolor("231 24 55") lpattern(solid) lwidth(0.25) ) 	///
	(scatter relative_sec lockdown_index_adj [aw=weights], 													///
		msize(0.4) mcolor(navy%70) mlwidth(0.25) 															///
	) 																										/// 
	(scatter relative_sec lockdown_index_adj, msymbol(none) mlabsize(8pt) 									///
		mlabel(noga2008_seco_select) mlabcolor(navy) mlabposition(5)  mlabgap(1.25) 						///
	) 																										/// 
	, 																										///
	xtitle(" " "Lockdown index" "(adjusted for public sector)" " ", size(10pt)) 							///
	xlabel(0(0.1)0.7, format(%3.2f) labsize(10pt)) 															///
	ytitle("Approved short-time work applications" "per worker, March-April 2020 (in %)" " ", size(10pt)) 	///
	ylabel(0(10)80, labsize(10pt)) 																			///
	legend(off) 																							///
	graphregion(color(white)) 																				/// 
	note("Source: Own calculation with SLFS 2018, O*NET, SECO labor market report and STATENT", size(8pt) span)	

graph export "C_03_scatter_stw_adj_lockdown_industry.pdf", replace

* Regression short-time work vs. Lockdown index (unadjusted)
reg relative_sec lockdown_index_adj [aw=weights], robust

* Export .csv file
keep noga2008_kza noga2008_kza_title relative_sec lockdown_index_adj weights
order noga2008_kza noga2008_kza_title relative_sec lockdown_index_adj weights
rename relative_sec genehmigte_STW
export delimited using "C_03_scatter_stw_adj_lockdown_industry.csv", replace


* ------------------------------------------------------------------------------
* C_03_03 Canton-level short-time work vs lockdown index, public sector adj.
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_company_canton.dta", clear
drop if company_canton<0

decode company_canton_title, gen(compc_title)
rename company_canton canton

merge 1:1 compc_title using "B_01_input_stw_cantons.dta", nogenerate

* Scatter short-time work vs. lockdown index [Figure 12]
twoway ///
	(lfit relative_ct lockdown_index_adj [aw=weights], lcolor("231 24 55") lpattern(solid) lwidth(0.25) )	///
	(scatter relative_ct lockdown_index_adj [aw=weights], 													///
		msize(0.4) mcolor(navy%70) mlwidth(0.25) 															///
	) 																										/// 
	(scatter relative_ct lockdown_index_adj, msymbol(none) mlabsize(7pt) 									///
		mlabel(canton) mlabcolor(navy) mlabposition(5)  mlabgap(1.25) 										///
	) 																										/// 
	, 																										///
	xtitle(" " "Lockdown index" "(adjusted for public sector)" " ", size(10pt)) 							///
	xlabel(0.24(0.02)0.38, format(%3.2f) labsize(10pt)) 													///
	ytitle("Approved short-time work applications" "per worker, March-April 2020 (in %)" " ", size(10pt)) 	///
	ylabel(25(5)50, labsize(10pt)) 																			///
	legend(off) 																							///
	graphregion(color(white)) 																				/// 
	note("Source: Own calculations with SLFS 2018, O*NET, SECO labor market data and STATENT", size(8pt) span)

graph export "C_03_scatter_stw_lockdown_canton.pdf", replace

* Regression short-time work vs. lockdown index
reg relative_ct lockdown_index_adj [aw=weights], robust

* Export .csv file
keep canton company_canton_title relative_ct lockdown_index_adj weights
order canton company_canton_title relative_ct lockdown_index_adj weights
rename relative_ct genehmigte_STW
export delimited using "C_03_scatter_stw_lockdown_canton.csv", replace

* ------------------------------------------------------------------------------
* C_03_04 Canton-level comparis usage vs lockdown index, public sector adj.
* ------------------------------------------------------------------------------

* Import indexes and weights
use "B_03_privacyconform_company_canton.dta", clear
drop if company_canton<0
rename company_canton canton


* Merge with comparis data
merge 1:1 canton using "B_01_input_comparis_users_canton.dta", nogenerate

* Scatter unemployment vs. lockdown index
twoway ///
	(lfit sh_ka lockdown_index_adj if german==1 [aw=weights], lcolor("231 24 55") lpattern(solid) lwidth(0.25)) 	///
	(scatter sh_ka lockdown_index_adj if german==1 [aw=weights], 													///
		msize(0.4) mcolor(navy%70) mlwidth(0.25) 																	///
	) 																												/// 
	(scatter sh_ka lockdown_index_adj if german==1, msymbol(none) 													///
		mlabel(canton) mlabsize(7.5pt) mlabcolor(navy) mlabposition(3)  mlabgap(1.5) 								///
	) 																												/// 
	, 																												///
	xtitle(" " "Lockdown index" "(adjusted for public sector)" " ", size(10pt)) 									///
	xlabel(0.23(0.03)0.39, format(%3.2f) labsize(10pt)) 															///
	ytitle("User share of the short-time work" "calculator of comparis.ch (in %)" " ", size(10pt)) 					///
	ylabel(4(1)7, glwidth(0.15) labsize(10pt)) 																		///
	legend(off) 																									///
	graphregion(color(white)) 																						///
	note("Source: Own calculations with SLFS 2018, O*NET and aggregated user data from comparis.ch", size(8pt) span)

graph export "C_03_scatter_comparis_lockdown_canton.pdf", replace

* Regression comparis users vs. lockdown index
reg sh_ka lockdown_index_adj if german==1 [aw=weights], robust

* Export .csv file
keep if german==1
keep canton_str canton_str_short sh_ka lockdown_index_adj weights
order canton_str canton_str_short sh_ka lockdown_index_adj weights
rename sh_ka Comparis_users_share
export delimited using "C_03_scatter_comparis_lockdown_canton.csv", replace

* ------------------------------------------------------------------------------
* C_03_05 Industry-level unemployment vs lockdown index 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_noga2008_seco.dta", clear

merge 1:1 noga2008_seco using "B_01_input_unemp_noga.dta", nogenerate

drop if noga2008_seco_title==""
order noga2008_seco noga2008_seco_title lockdown_index  lockdown_index_adj home_office_index   unemp_abs_mar2019 unemp_abs_apr2019 unemp_abs_feb2020 unemp_abs_mar2020 unemp_abs_apr2020 d_pct_unempl_feb20_mar20 d_pct_unempl_mar19_mar20 weights

gen avg_unemp_mar_apr_19=(unemp_abs_mar2019+unemp_abs_apr2019)/2
gen avg_unemp_mar_apr_20=(unemp_abs_mar2020+unemp_abs_apr2020)/2

*gen d_unemp_mar_apr=100*(unemp_abs_apr2020-unemp_abs_feb2020)/avg_unemp_mar_apr_19
gen d_unemp_mar     =100*(unemp_abs_mar2020/unemp_abs_mar2019)-100
gen d_unemp_mar2    =100*(unemp_abs_mar2020/unemp_abs_feb2020)-100
gen d_unemp_mar3    =100*((unemp_abs_mar2020/unemp_abs_feb2020-1)-(unemp_abs_mar2019/unemp_abs_feb2019-1))
gen d_unemp_apr     =100*(unemp_abs_apr2020/unemp_abs_apr2019)-100
gen d_unemp_apr2    =100*(unemp_abs_apr2020/unemp_abs_mar2020)-100
gen d_unemp_apr3    =100*((unemp_abs_apr2020/unemp_abs_mar2020-1)-(unemp_abs_apr2019/unemp_abs_mar2019-1))
gen d_unemp_mar_apr =100*(avg_unemp_mar_apr_20/avg_unemp_mar_apr_19)-100

* Scatter plots and bivariate regressions**
capture drop noga2008_seco_select
generate noga2008_seco_select = ""

replace noga2008_seco_select = "Hospitality" if noga2008_seco=="55-56"
replace noga2008_seco_select = "Health and social care" if noga2008_seco=="86-88"
replace noga2008_seco_select = noga2008_seco_title_eng if noga2008_seco=="47"
replace noga2008_seco_select = "Agriculture" if noga2008_seco=="01-03"
replace noga2008_seco_select = "Education" if noga2008_seco=="85"
replace noga2008_seco_select = noga2008_seco_title_eng if noga2008_seco=="28"


* Scatter unemployment vs. lockdown index  (April 2020 compared to April 2019) [Figure 15]
twoway ///
	(lfit d_unemp_apr lockdown_index [aw=unemp_abs_apr2019], lcolor("231 24 55") lpattern(solid) lwidth(0.25)) 	///
	(scatter d_unemp_apr lockdown_index [aw=unemp_abs_apr2019], 												///
		msize(0.4) mcolor(navy%70) mlwidth(0.25) 																///
	) 																											/// 
	(scatter d_unemp_apr lockdown_index, msymbol(none) mlabsize(8pt) 											///
		mlabel(noga2008_seco_select) mlabcolor(navy) mlabposition(5)  mlabgap(1.25) 							///
	) 																											/// 
	, 																											///
	xtitle(" " "Lockdown index", size(10pt)) 																	///
	xlabel(0(0.1)0.7, format(%2.1f) labsize(10pt)) 																///
	ytitle("Increase in unemployment" "compared to year before, April 2020 (in %)" " ", size(10pt)) 			///
	ylabel(0(20)100, labsize(small)) 																			///
	legend(off) 																								///
	graphregion(color(white)) 																					/// 
	note(" " "Source: Own calculations with SLFS 2018, O*NET and SECO labor market data", size(8pt) span)
	
graph export "C_03_scatter_unemp_lockdown_industry.pdf", replace

* Regression unemployment vs. Lockdown index
reg d_unemp_apr lockdown_index [aw=unemp_abs_apr2019], robust

* Export .csv file
keep noga2008_seco noga2008_seco_title d_unemp_apr lockdown_index unemp_abs_apr2019
order noga2008_seco noga2008_seco_title d_unemp_apr lockdown_index unemp_abs_apr2019
export delimited using "C_03_scatter_unemp_lockdown_industry.csv", replace

* ------------------------------------------------------------------------------
* C_03_06 Canton-level unemployment vs lockdown index 
* ------------------------------------------------------------------------------

* Import data
use "B_03_privacyconform_company_canton.dta", clear
drop if company_canton<0

* Select used variables
decode company_canton_title, gen(compc_title)
rename company_canton canton

merge 1:1 compc_title using "B_01_input_unemp_canton.dta", nogenerate

* Scatter UE vs. Lockdown index  [Figure 16]
twoway ///
	(lfit d_unemp_apr lockdown_index [aw=unemp_apr19], lcolor("231 24 55") lpattern(solid) lwidth(0.25)) 	///
	(scatter d_unemp_apr lockdown_index [aw=unemp_apr19], 													///
		msize(0.4) mcolor(navy%70) mlwidth(0.25) 															///
	) 																										/// 
	(scatter d_unemp_apr lockdown_index, msymbol(none) mlabsize(7pt) 										///
		mlabel(canton) mlabcolor(navy) mlabposition(5)  mlabgap(1.25) 										///
	) 																										/// 
	,																										///
	xtitle(" " "Lockdown index" " ", size(10pt)) 															///
	xlabel(0.26(0.02)0.4, format(%3.2f) labsize(10pt)) 														///
	ytitle("Increase in unemployment" "compared to year before, April 2020 (in %)" " ", size(10pt)) 		///
	ylabel(0(20)120, labsize(10pt)) 																		///
	legend(off) 																							///
	graphregion(color(white)) 																				/// 
	note(" " "Source: Own calculations with SLFS 2018, O*NET and SECO labor market data", size(8pt) span)

graph export "C_03_scatter_unemp_lockdown_canton.pdf", replace

* Regression unemployment vs. Lockdown index
reg d_unemp_apr lockdown_index [aw=unemp_apr19], robust

* Export .csv file
keep canton d_unemp_apr lockdown_index unemp_apr19
order canton d_unemp_apr lockdown_index unemp_apr19
export delimited using "C_03_scatter_unemp_lockdown_canton.csv", replace
